<?php

if(!defined('CMS_ADMIN')) {
	die("Illegal File Access");
}

if (defined('iS_RADMIN')) {
	include_once("page_header.php");

	$if_show = 1;
	$err_region = $err_address = $err_phone = $err_email =  $err_website ="";
	if(isset($_POST['subup']) && $_POST['subup'] == 1) {
		$region = trim(stripslashes(resString($_POST['region'])));
		$address = trim(stripslashes(resString($_POST['address'])));
		$phone =$_POST['phone'];
		$email =$_POST['email'];
		$website =$_POST['website'];
		$if_show = intval($_POST['ifshow']);
		$bmodule = $_POST['bmodule'];

	if(@in_array("all",$bmodule)) {$bmodule_up ="all"; }else{
		$bmodule_up = @implode("|",$bmodule);
	}
	if(empty($bmodule_up)) { $bmodule_up = "all"; }

	if(empty($region)) {
		$err_title = "<font color=\"red\">"._ERROR1."</font><br>";
		$err = 1;
	}
	if(empty($address)) {
		$err_title = "<font color=\"red\">"._ERROR2."</font><br>";
		$err = 1;
	}
	if(empty($phone)) {
		$err_title = "<font color=\"red\">"._ERROR3."</font><br>";
		$err = 1;
	}
	if(!$err) {
		$db->sql_query("INSERT INTO ".$prefix."_allocated ( region, address, phone,email,website,times, alanguage,if_show) VALUES ( '$region', '$address', '$phone', '$email', '$website','".time()."', '$currentlang','$if_show')");
		updateadmlog($admin_ar[0], $adm_modname, _MODTITLE, _ADD);
		header("Location: modules.php?f=$adm_modname");
	}
	}

	echo "<script language=\"javascript\">\n";
	echo "	function check(f) {\n";
	echo "		if(f.region.value =='') {\n";
	echo "			alert('"._ERROR1."');\n";
	echo "			f.title.focus();\n";
	echo "			return false;\n";
	echo "		}	\n";
	echo "		if(f.address.value =='') {\n";
	echo "			alert('"._ERROR2."');\n";
	echo "			f.address.focus();\n";
	echo "			return false;\n";
	echo "		}	\n";

	echo "		if(f.phone.value =='') {\n";
	echo "			alert('"._ERROR3."');\n";
	echo "			f.phone.focus();\n";
	echo "			return false;\n";
	echo "		}	\n";
	
	echo "		f.submit.disabled = true;\n";
	echo "		return true;	\n";
	echo "	}	\n";
	echo "</script>	\n";
	ajaxload_content();

	echo "<div id=\"".$adm_modname."_main\"><form action=\"modules.php?f=$adm_modname&do=$do\" method=\"POST\" enctype=\"multipart/form-data\" onsubmit=\"return check(this);\"><table border=\"0\" width=\"100%\" cellspacing=\"0\" cellpadding=\"4\" class=\"tableborder\">\n";
	echo "<tr><td class=\"header\" colspan=\"2\">"._CREATEMENU."</td></tr>";
	echo "<tr>\n";
	echo "<tr>\n";
	echo "<td width=\"20%\" align=\"right\" class=\"row1\"><b>"._TITLE_REGION."</b></td>\n";
	echo "<td class=\"row2\">$err_region<input type=\"text\" name=\"region\" value=\"\" size=\"60\"></td>\n";
	echo "</tr>\n";
	
	echo "<tr>\n";
	echo "<td width=\"20%\" align=\"right\" class=\"row1\"><b>"._TITLE_ADDRESS."</b></td>\n";
	echo "<td class=\"row2\">$err_address<input type=\"text\" name=\"address\" value=\"\" size=\"60\"></td>\n";
	echo "</tr>\n";
	
	echo "<tr>\n";
	echo "<td width=\"20%\" align=\"right\" class=\"row1\"><b>"._TITLE_PHONE."</b></td>\n";
	echo "<td class=\"row2\">$err_phone<input type=\"text\" name=\"phone\" value=\"\" size=\"60\"></td>\n";
	echo "</tr>\n";
	
	echo "<tr>\n";
	echo "<td width=\"20%\" align=\"right\" class=\"row1\"><b>"._TITLE_EMAIL."</b></td>\n";
	echo "<td class=\"row2\">$err_email<input type=\"text\" name=\"email\" value=\"\" size=\"60\"></td>\n";
	echo "</tr>\n";
	
	echo "<tr>\n";
	echo "<td width=\"20%\" align=\"right\" class=\"row1\"><b>"._TITLE_WEBSITE."</b></td>\n";
	echo "<td class=\"row2\">$err_website<input type=\"text\" name=\"website\" value=\"\" size=\"60\"></td>\n";
	echo "</tr>\n";
	
	echo "<tr>\n";
	echo "<td align=\"right\" class=\"row1\"><b>"._SHOW."</b></td>\n";
	if($if_show == 0) {
		echo "<td  class=\"row2\"><input type=\"radio\" name=\"ifshow\" value=\"1\">"._YES." &nbsp;&nbsp;"
		."<input type=\"radio\" name=\"ifshow\" value=\"0\" checked>"._NO."</td>\n";
	} else {
		echo "<td  class=\"row2\"><input type=\"radio\" name=\"ifshow\" value=\"1\" checked>"._YES." &nbsp;&nbsp;"
		."<input type=\"radio\" name=\"ifshow\" value=\"0\">"._NO."</td>\n";
	}
	echo "</tr>\n";
	echo "<input type=\"hidden\" name=\"subup\" value=\"1\">";
	echo "<tr><td class=\"row3\">&nbsp;</td><td class=\"row3\"><input type=\"submit\" name=\"submit\" value=\""._ADD."\" class=\"input1\"></td></tr>";
	echo "</table></form><br>";

	$result = $db->sql_query("SELECT id, region, address, phone,email,website,times,if_show FROM ".$prefix."_allocated WHERE alanguage='$currentlang' ORDER BY times DESC");
	if($db->sql_numrows($result) > 0) {
		echo "<script language=\"javascript\" type=\"text/javascript\">\n";
		echo "function check_uncheck(){\n";
		echo "	var f= document.frm;\n";
		echo "	if(f.checkall.checked){\n";
		echo "		CheckAllCheckbox(f,'bnid[]');\n";
		echo "	}else{\n";
		echo "		UnCheckAllCheckbox(f,'bnid[]');\n";
		echo "	}			\n";
		echo "}\n";
		echo "	function checkQuick(f) {\n";
		echo "		if(f.f.value =='') {\n";
		echo "			f.f.focus();\n";
		echo "			return false;\n";
		echo "		}\n";
		echo "		f.submit.disabled = true; \n";
		echo "		return true;		\n";
		echo "	}	\n";
		echo "</script>\n";
		echo "<form action=\"modules.php?f=$adm_modname&do=$do\" name=\"frm\" id=\"frm\" method=\"POST\" onsubmit=\"return checkQuick(this);\"><table border=\"0\" width=\"100%\" cellspacing=\"0\" cellpadding=\"4\" class=\"tableborder\">\n";
		echo "<tr><td colspan=\"9\" class=\"header\">".ALL_LINKS."</td></tr>";
		echo "<tr>";
		echo "<td class=\"row1sd\" width=\"10\"><input type=\"checkbox\" name=\"checkall\" onclick=\"javascript:check_uncheck();\" title=\""._CHECKALL."\"></td>\n";
		echo "<td class=\"row3sd\" align=\"center\" width=\"80\">"._TITLE_REGION."</td>\n";
		echo "<td class=\"row1sd\" align=\"center\" width=\"80\">"._TITLE_ADDRESS."</td>\n";
		echo "<td class=\"row3sd\" align=\"center\" width=\"80\">"._SHOW."</td>\n";
		echo "<td class=\"row1sd\" align=\"center\" width=\"80\">".TIMES."</td>\n";
		echo "<td class=\"row1sd\" align=\"center\" width=\"80\">"._TITLE_PHONE."</td>\n";
		echo "<td class=\"row1sd\" align=\"center\" width=\"80\">"._TITLE_EMAIL."</td>\n";
		echo "<td class=\"row3sd\" align=\"center\" width=\"30\">"._EDIT."</td>\n";
		echo "<td class=\"row1sd\" align=\"center\" width=\"30\">"._DELETE."</td>\n";
		echo "</tr>\n";
		while(list($id, $region, $address, $phone,$email,$website,$times,$if_show) = $db->sql_fetchrow($result)) {
		if ($ajax_active == 1) {
				switch($if_show) {
					case 1: $if_show = "<a href=\"?f=".$adm_modname."&do=status&id=$id&stat=0\" title=\""._DEACTIVATE."\" onclick=\"return aj_base_status($id,0,'$adm_modname','status','');\"><img border=\"0\" src=\"images/view.png\"></a>"; break;
					case 0: $if_show = "<a href=\"?f=".$adm_modname."&do=status&id=$id&stat=1\" title=\""._ACTIVE."\" onclick=\"return aj_base_status($id,1,'$adm_modname','status','');\"><img border=\"0\" src=\"images/viewo.png\"></a>"; break;
				}
			}
			else {
				switch($if_show) {
					case 1: $if_show = "<a href=\"?f=$adm_modname&do=status&id=$id&stat=0\" info=\""._DEACTIVATE."\"><img border=\"0\" src=\"images/view.png\"></a>"; break;
					case 0: $if_show = "<a href=\"?f=$adm_modname&do=status&id=$id&stat=1\" info=\""._ACTIVE."\"><img border=\"0\" src=\"images/viewo.png\"></a>"; break;
				}
			}
			$date=date('d/m/Y H:i',$times);
			echo "<tr>\n";
			echo "<td class=\"row1\" width=\"10\"><input type=\"checkbox\" name=\"bnid[]\" value=\"$id\"></td>\n";
			echo "<td class=\"row3\" align=\"center\" width=\"150\">";
				echo "<b>$region</b>";
			echo "</td>\n";
			echo "<td class=\"row3\" align=\"center\" width=\"200\">$address</td>\n";
			echo "<td class=\"row1\" align=\"center\">$if_show</td>\n";
			echo "<td class=\"row3\" align=\"center\" width=\"100\">$date</td>\n";
			echo "<td class=\"row3\" align=\"center\" width=\"100\">$phone</td>\n";
			echo "<td class=\"row3\" align=\"center\" width=\"100\">$email</td>\n";
			echo "<td class=\"row3\" align=\"center\" width=\"30\"><a href=\"?f=$adm_modname&do=edit&id=$id\" info=\""._EDIT."\"><img border=\"0\" src=\"images/edit.png\"></a></td>\n";
			echo "<td class=\"row3\" align=\"center\" width=\"30\">";
			echo "<a href=\"?f=$adm_modname&do=delete&id=$id\" info=\""._DELETE."\" onclick=\"return confirm('"._DELETEASK1."');\"><img border=\"0\" src=\"images/delete.png\">";
			echo "</td>\n";
			echo "</tr>\n";
		}
		echo "<input type=\"hidden\" name=\"do\" value=\"quick\">";
		echo "<tr><td colspan=\"8\" class=\"row1\"><select name=\"v\">";
		echo "<option value=\"\">&raquo; "._QUICKDO."</option>";
		echo "<option value=\"1\">&raquo; "._QUICKDO_1."</option>";
		echo "<option value=\"2\">&raquo; "._QUICKDO_2."</option>";
		echo "<option value=\"3\">&raquo; "._QUICKDO_3."</option>";
		echo "</select> <input type=\"submit\" name=\"submit\" value=\""._DOACTION."\"></td></tr>";
		echo "</table><br>";
		OpenDiv();
		echo "* "._NOTES."";
		CloseDiv();
		echo "</div>";
	}

	include_once("page_footer.php");
} else {
	//header("Location: body.php");
	echo "Illegal File Access";
}
?>